#include <SDL/SDL_image.h>
#include "MainWindow.h"
#include "PushButton.h"

Image PushButton::m_sprites[3];

PushButton::PushButton(IScreen* _caller, std::string const& _text)
: AButton(_caller, _text)
{
	if (m_sprites[0].Surface == NULL)
	{
		m_sprites[0].Surface = IMG_Load("images\\PushButton_released.png");
		m_sprites[1].Surface = IMG_Load("images\\PushButton_pressed.png");
		m_sprites[2].Surface = IMG_Load("images\\PushButton_hovered.png");
		m_sprites[0].setTransparence();
		m_sprites[1].setTransparence();
		m_sprites[2].setTransparence();
	}
	m_currentSprite = &m_sprites[0];
	//m_callBack = (ButtonCallBack)&PushButton::callBack;
	//(this->*CallBack)();
}

PushButton::~PushButton()
{
}

void PushButton::updateState()
{
	if (m_currentState == AButton::ButtonState::PRESSED)
	{
		m_currentSprite = &m_sprites[1];
	}
	else if (m_currentState == AButton::ButtonState::HOVERED)
	{
		m_currentSprite = &m_sprites[2];
	}
	else
	{
		m_currentSprite = &m_sprites[0];
	}
}

void PushButton::setPosition(int _x, int _y)
{
	this->AButton::setPosition(_x, _y);
	if (m_text.Surface != NULL)
	{	
		if (m_currentSprite != NULL)
		{
			if (m_currentSprite->Surface != NULL)
			{
				m_text.Position.x = _x + m_currentSprite->Surface->w /2 - m_text.Surface->w / 2;
				m_text.Position.y = _y + m_currentSprite->Surface->h / 2 - m_text.Surface->h / 2;
			}
		}
	}
}